//
//  SemaphoreLock.m
//  GCDDemo
//
//  Created by everyu on 2018/6/5.
//  Copyright © 2018年 everyu. All rights reserved.
//

#import "SemaphoreLock.h"
@interface SemaphoreLock ()
{
    dispatch_semaphore_t _sema;
}

@end

@implementation SemaphoreLock

- (instancetype)init
{
    if (self = [super init]) {
        _sema = dispatch_semaphore_create(1);
    }
    return self;
}

- (NSInteger)lock
{
   return  dispatch_semaphore_wait(_sema, DISPATCH_TIME_FOREVER);
}

- (NSInteger)unlock
{
    return dispatch_semaphore_signal(_sema);
}
@end
